SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "0")
SET(CPACK_PACKAGE_VERSION_PATCH "0")
IF(APPLE)
    SET(CPACK_GENERATOR "DragNDrop")
ELSE()
    SET(CPACK_GENERATOR "ZIP")
ENDIF()
set(CPACK_SOURCE_GENERATOR ZIP)

IF(EXISTS ${PROJECT_SOURCE_DIR}/.git)
    FIND_PROGRAM(git_PROG NAMES git git.cmd)
    MARK_AS_ADVANCED(git_PROG)
    IF(git_PROG)
        EXECUTE_PROCESS(
            COMMAND ${git_PROG} describe --long
            WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
            OUTPUT_VARIABLE git_OUTPUT
            RESULT_VARIABLE git_RESULT)
        IF(${git_RESULT} EQUAL 0)
            STRING(REGEX REPLACE "v([0-9])+.[0-9]+-[0-9]+-g[0-9a-f]+.*" "\\1" CPACK_PACKAGE_VERSION_MAJOR "${git_OUTPUT}")
            STRING(REGEX REPLACE "v[0-9]+.([0-9])+-[0-9]+-g[0-9a-f]+.*" "\\1" CPACK_PACKAGE_VERSION_MINOR "${git_OUTPUT}")
            STRING(REGEX REPLACE "v[0-9]+.[0-9]+-([0-9]+-g[0-9a-f]+).*" "\\1" CPACK_PACKAGE_VERSION_PATCH "${git_OUTPUT}")
        ELSE()
            MESSAGE(WARNING ${git_OUTPUT})
        ENDIF()
    ENDIF()
ENDIF()

SET(CPACK_PACKAGE_VERSION "v${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-${CPACK_PACKAGE_VERSION_PATCH}")
MESSAGE(STATUS "VERSION: ${CPACK_PACKAGE_VERSION}")

SET(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
IF(${CPACK_SYSTEM_NAME} MATCHES Windows)
    IF(CMAKE_CL_64)
        SET(CPACK_SYSTEM_NAME win64)
    ELSE()
        SET(CPACK_SYSTEM_NAME win32)
    ENDIF()
ENDIF()
IF(${CPACK_SYSTEM_NAME} MATCHES Darwin)
    SET(CPACK_SYSTEM_NAME mac)
ENDIF()

SET(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME})
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-src")
SET(CPACK_SOURCE_IGNORE_FILES "/build/;/.git/")
